package com.hu.service.impl;

import com.hu.config.comment.ResponseResult;
import com.hu.dal.mapper.InfoMapper;
import com.hu.dal.pojo.Info;
import com.hu.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class InfoServiceImpl implements InfoService {
    @Autowired
    InfoMapper infoMapper;

    @Override
    public ResponseResult insert(Info info) {
        infoMapper.insert(info);
        return ResponseResult.success("ok");
    }

    @Override
    public ResponseResult getAll(int page, int pageSize) {
        int offset = pageSize * (page - 1);
         List l=  infoMapper.getAll(offset,pageSize);
        int count=infoMapper.getCount();
        Map m =new HashMap();
        m.put("count",count);
        m.put("list",l);
        return ResponseResult.success("ok",m);
    }

    @Override
    public ResponseResult getById(int id) {
        return ResponseResult.success("ok",infoMapper.getById(id));
    }

    @Override
    public ResponseResult update(Info info) {
        infoMapper.update(info);
        return ResponseResult.success("ok");
    }

    @Override
    public ResponseResult delete(int id) {
        infoMapper.delete(id);
        return ResponseResult.success("ok");
    }
}
